package mytest.wd2;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;

public class Test2 {

    public static void main(String[] args) {

        String path = "E:\\QQandWeChat downloads\\WXWork\\1688857665631195\\Cache\\File\\2024-08\\03f242ce-9625-456a-94de-dd0481bde308(1).csv";

        List<String> lists = readFile(path);
        HashMap<String, Set<String>> hashMap2 = new HashMap<>();

        for (String list : lists) {
            Map<String, Object> map = JSONObject.parseObject(list);
            String sessionGid = (String) map.get("session_gid");
            String appName = (String) map.get("appName");
            hashMap2.computeIfAbsent(sessionGid, l -> new HashSet<>()).add(appName);
        }

        for (Map.Entry<String, Set<String>> entry : hashMap2.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue().size());
        }

        System.out.println("--------------------------------");
        Set<String> set1 = new HashSet<>();

        for (Map.Entry<String, Set<String>> entry : hashMap2.entrySet()) {
            Set<String> value = entry.getValue();
            for (String s : value) {
                set1.add(s);
            }
        }
        System.out.println(set1.size());

        System.out.println("------------------------------------");

        int temp = 0;
        for (Map.Entry<String, Set<String>> entry : hashMap2.entrySet()) {
            String key = entry.getKey();
            Set<String> value = entry.getValue();
            for (String s : value) {
                System.out.println(key + " : " + s);
                temp ++;
            }
        }
        System.out.println(temp);

//        System.out.println(lists.size());

    }
    private static List<String> readFile(String path) {
        List<String> lines = new ArrayList<>();
        FileReader fr = null;
        try {
            fr = new FileReader(path);
            BufferedReader br = new BufferedReader(fr);
            String line = "";
            String[] arrs = null;
            while ((line = br.readLine()) != null) {
                lines.add(line);
            }
            br.close();
            fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lines;
    }
}
